<template>
<div class="order_page">
    <head-top head-title="二手交易" go-back='true'></head-top>

    <!--循环遍历获取活动列表-->
    <!-- v-for="(item, index) in foodTypes" :key="index" -->
    <div class="swiper-slide food_types_container">
        <!-- <router-link :to="{path: '/food', query: {geohash, title: foodItem.title, restaurant_category_id: getCategoryId(foodItem.link)}}" v-for="foodItem in item" :key="foodItem.id" class="link_to_food">
            <figure>
                <img :src="imgBaseUrl + foodItem.image_url" />
                <figcaption>{{foodItem.title}}</figcaption>
            </figure>
            </router-link>
            -->

        <div class="link_to_food">
            <router-link :to="{path: '/selectgoods', query:{geohash, goodsselect:'电视机'}}">
                <figure>
                    <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600144058043&di=7f8d207dab8024a0b43ba032c56ec452&imgtype=0&src=http%3A%2F%2Fimg1.100ye.com%2Fimg1%2F4%2F1294%2F1310%2F10942310%2Fmsgpic%2F62802296.jpg" />
                    <figcaption>电视机</figcaption>
                </figure>
            </router-link>
        </div>

        <div class="link_to_food">
            <router-link :to="{path: '/selectgoods', query:{geohash, goodsselect:'自行车'}}">
                <figure>
                    <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2845690463,2197626679&fm=26&gp=0.jpg" />
                    <figcaption>自行车</figcaption>
                </figure>
            </router-link>
        </div>
        <div class="link_to_food">
            <router-link :to="{path: '/selectgoods', query:{geohash, goodsselect:'电冰箱'}}">
                <figure>
                    <img src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=424653524,3755690511&fm=26&gp=0.jpg" />
                    <figcaption>电冰箱</figcaption>
                </figure>
            </router-link>
        </div>
        <div class="link_to_food">
            <figure>
                <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3639173815,3359158807&fm=26&gp=0.jpg" />
                <figcaption>洗衣机</figcaption>
            </figure>
        </div>
        <div class="link_to_food">
            <figure>
                <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3430238077,1029127631&fm=26&gp=0.jpg" />
                <figcaption>扫地机器人</figcaption>
            </figure>
        </div>
        <div class="link_to_food">
            <figure>
                <img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1062706841,1471925674&fm=26&gp=0.jpg" />
                <figcaption>空调</figcaption>
            </figure>
        </div>
        <div class="link_to_food">
            <figure>
                <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3478919816,1529207950&fm=26&gp=0.jpg" />
                <figcaption>微波炉</figcaption>
            </figure>
        </div>
        <div class="link_to_food">
            <figure>

                <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2485708438,3812763049&fm=26&gp=0.jpg" />
                <figcaption>衣物</figcaption>
            </figure>
        </div>
        <goodsList title="电视机">
        </goodsList>
    </div>

    <foot-guide></foot-guide>
    <transition name="loading">
        <!--加载图标-->
        <loading v-show="showLoading"></loading>
    </transition>
    <transition name="router-slid" mode="out-in">
        <router-view></router-view>
    </transition>
    <router-link to='/addgoods'>
        <button>
            <img class="add" :src="image" style="float:right;position: fixed;bottom: 3.5rem;right: 2.2rem;z-index: 9999;width:3rem;height:3rem" />
        </button>
    </router-link>
</div>
</template>

<script>
import {
    mapState,
    mapMutations
} from 'vuex'
import headTop from 'src/components/header/head'
import goodsList from 'src/page/secondHandArea/headpage/goods.vue'
import computeTime from 'src/components/common/computeTime'
import loading from 'src/components/common/loading'
import {
    getImgPath
} from 'src/components/common/mixin'
import footGuide from 'src/components/footer/footGuide'
import {
    getOrderList
} from 'src/service/getData'
import {
    loadMore
} from 'src/components/common/mixin'
import {
    imgBaseUrl
} from 'src/config/env'

export default {
    data() {
        return {
            orderList: null, //订单列表
            offset: 0,
            preventRepeat: false, //防止重复获取
            showLoading: true, //显示加载动画
            imgBaseUrl,
            image: require('src/images/add_address.png')
        }
    },
    mounted() {
        this.initData();
    },
    mixins: [loadMore],
    components: {
        headTop,
        footGuide,
        loading,
        computeTime,
        goodsList,
    },
    computed: {
        ...mapState([
            'userInfo', 'geohash'
        ]),

    },
    methods: {
        ...mapMutations([
            'SAVE_ORDER'
        ]),
        //初始化获取信息
        async initData() {
            if (this.userInfo && this.userInfo.user_id) {
                let res = await getOrderList(this.userInfo.user_id, this.offset);
                this.orderList = [...res];
                this.hideLoading();
            } else {
                this.hideLoading();
            }
        },
        //加载更多
        async loaderMore() {
            if (this.preventRepeat) {
                return
            }
            this.preventRepeat = true;
            this.showLoading = true;
            this.offset += 10;
            //获取信息
            let res = await getOrderList(this.userInfo.user_id, this.offset);
            this.orderList = [...this.orderList, ...res];
            this.hideLoading();
            if (res.length < 10) {
                return
            }
            this.preventRepeat = false;
        },
        //显示详情页
        showDetail(item) {
            this.SAVE_ORDER(item);
            this.preventRepeat = false;
            this.$router.push('/order/orderDetail');
        },
        //生产环境与发布环境隐藏loading方式不同
        hideLoading() {
            this.showLoading = false;
        },
    },
    watch: {
        userInfo: function (value) {
            if (value && value.user_id && !this.orderList) {
                this.initData();
            }
        }
    }
}
</script>

<style lang="scss" scoped>
@import 'src/style/mixin';

.food_types_container {
    margin-top: 50px;
    display: flex;
    flex-wrap: wrap;

    .link_to_food {
        width: 25%;
        padding: 0.3rem 0rem;
        @include fj(center);

        figure {
            img {
                margin-bottom: 0.3rem;
                @include wh(1.8rem, 1.8rem);
            }

            figcaption {
                text-align: center;
                @include sc(0.55rem, #666);
            }
        }
    }
}

figcaption {
    text-align: center;
    @include sc(0.55rem, #666);
}

.order_page {
    background-color: #f1f1f1;
    margin-bottom: 1.95rem;

    p,
    span,
    h4 {
        font-family: Helvetica Neue, Tahoma, Arial;
    }
}

.order_list_ul {
    padding-top: 1.95rem;

    .order_list_li {
        background-color: #fff;
        display: flex;
        margin-bottom: 0.5rem;
        padding: .6rem .6rem 0;

        .restaurant_image {
            @include wh(2rem, 2rem);
            margin-right: 0.4rem;
        }

        .order_item_right {
            flex: 5;

            .order_item_right_header {
                border-bottom: 0.025rem solid #f5f5f5;
                padding-bottom: .3rem;
                @include fj;

                .order_header {
                    h4 {
                        display: flex;
                        align-items: center;
                        justify-content: flex-start;
                        @include sc(.75rem, #333);
                        line-height: 1rem;
                        width: 9rem;

                        .arrow_right {
                            @include wh(.4rem, .4rem);
                            fill: #ccc;
                            margin-right: .2rem;
                        }
                    }

                    .order_time {
                        @include sc(.55rem, #999);
                        line-height: .8rem;
                    }
                }

                .order_status {
                    @include sc(.6rem, #333);
                }
            }

            .order_basket {
                @include fj;
                line-height: 2rem;
                border-bottom: 0.025rem solid #f5f5f5;

                .order_name {
                    @include sc(.6rem, #666);
                    width: 10rem;
                }

                .order_amount {
                    @include sc(.6rem, #f60);
                    font-weight: bold;
                }
            }

            .order_again {
                text-align: right;
                line-height: 1.6rem;

                .buy_again {
                    @include sc(.55rem, #3190e8);
                    border: 0.025rem solid #3190e8;
                    padding: .1rem .2rem;
                    border-radius: .15rem;
                }
            }
        }
    }
}

.loading-enter-active,
.loading-leave-active {
    transition: opacity .7s
}

.loading-enter,
.loading-leave-active {
    opacity: 0
}

.router-slid-enter-active,
.router-slid-leave-active {
    transition: all .4s;
}

.router-slid-enter,
.router-slid-leave-active {
    transform: translate3d(2rem, 0, 0);
    opacity: 0;
}
</style>
